package com.mmc.service.email.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mmc.domain.email.MailBean;
import com.mmc.mapper.email.EmailMapper;
import com.mmc.service.email.EmailService;
@Service
@Transactional
public class EmailServiceImpl implements EmailService{
	@Autowired
	private EmailMapper emailMapper;
	
	@Override
	public List<MailBean> getAllMails(String userId) {
		return this.emailMapper.getAllMails(userId);
	}

	@Override
	public void saveEmail(MailBean mailBean) {
		mailBean.setId(UUID.randomUUID().toString());
		mailBean.setStatus(1);//暂存
		mailBean.setCreateTime(new Date());//创建时间
		mailBean.setUserId("1");//TODO 暂时写死，应该去当前用户的id
		this.emailMapper.saveEmail(mailBean);
	}

	@Override
	public void updateEmail(MailBean mailBean) {
		this.emailMapper.updateEmail(mailBean);
	}

	@Override
	public void deleteEmail(String id) {
		this.emailMapper.deleteEmail(id);
	}

	@Override
	public MailBean getById(String id) {
		return this.emailMapper.getById(id);
	}

	@Override
	public void deleteEmails(String[] ids) {
		for (int i = 0; i < ids.length; i++) {
			this.deleteEmail(ids[i]);
		}
	}
	
}
